﻿using System;
using System.ComponentModel;
using System.Drawing;
using Microsoft.WowAddonStudio.FrameXml.Components.Actions;
using Microsoft.WowAddonStudio.FrameXml.Components.Events;
using Microsoft.WowAddonStudio.FrameXml.Components.Support;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames;
using Action=Microsoft.WowAddonStudio.FrameXml.Components.Actions.Action;
using Button=Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames.Button;
using ButtonState=Microsoft.WowAddonStudio.FrameXml.Serialization.ButtonState;
using Color=System.Drawing.Color;

namespace Microsoft.WowAddonStudio.FrameXml.Components
{
    [ToolboxBitmap(typeof (System.Windows.Forms.Button), "Button.bmp")]
    [ToolboxItemFilter("WowAddonStudio", ToolboxItemFilterType.Require)]
    [EventGroup(EventGroup.Button, EventName.OnClick)]
    public class ButtonControl : FrameControl
    {
        private const ButtonState currentState = ButtonState.Normal;

        /// <summary>
        /// Initializes a new instance of the <see cref="ButtonControl"/> class.
        /// </summary>
        public ButtonControl()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ButtonControl"/> class.
        /// </summary>
        /// <param name="button">The button.</param>
        public ButtonControl(Button button)
            : base(button)
        {
        }

        /// <summary>
        /// Gets the type of the serialization object this control manages.
        /// </summary>
        public override Type SerializationObjectType
        {
            get { return typeof (Button); }
        }

        /// <summary>
        /// Gets the button.
        /// </summary>
        public Button Button
        {
            get { return SerializationObject as Button; }
        }

        /// <summary>
        /// Gets the default size of a FrameXML control.
        /// </summary>
        /// <value></value>
        protected override Size DefaultSize
        {
            get { return new Size(75, 23); }
        }

        /// <summary>
        /// Draws the FrameXML control.
        /// </summary>
        /// <param name="graphics">The <see cref="FrameXmlGraphics"/> context to draw to.</param>
        /// <param name="rectangle">The <see cref="Rectangle"/> to draw to.</param>
        public override bool DrawControl(FrameXmlGraphics graphics, Rectangle rectangle)
        {
            return graphics.DrawButton(Button, currentState, rectangle);
        }

        /// <summary>
        /// Gets the actions for the control.
        /// </summary>
        /// <returns>
        /// An array of <see cref="System.Action"/> instances.
        /// </returns>
        public override Action[] GetActions()
        {
            return new Action[]
                       {
                           new SetDefaultValueAction(this, "ButtonText")
                               {
                                   DefaultValue = new FontString
                                                      {
                                                          Color = Serialization.Color.FromColor(Color.Yellow),
                                                          Font = @"Fonts\FRIZQT__.TTF",
                                                          FontHeight = new FontHeight {AbsValue = new AbsValue {Value = 12}}
                                                      }
                               },
                           new SetDefaultValueAction(this, "PushedTextOffset")
                               {
                                   DefaultValue = new Dimension {AbsDimension = new AbsDimension {X = 1, Y = 1}}
                               }
                       };
        }
    }
}